import signal
import asyncio
from functools import partial

signals =[signal.Signals.SIGINT,signal.Signals.SIGTERM]

def sigint_handler(signame,*,loop):
    print(f"终止循环，由于收到信号{signame} ")
    loop.stop()

def signal_handler(signame,*,loop):
    print(f"终止循环，由于收到信号{signame} ")
    loop.stop()

loop = asyncio.get_event_loop()
try:
    for item in signals:
        print(item)
        loop.add_signal_handler(item,partial(signal_handler,"SSS",loop=loop))
    loop.run_forever()
finally:
    loop.close()

print("OVER...")
